package com.myclover.db.service;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBOpenHelper extends SQLiteOpenHelper
{
	private static final String DBNAME = "person.db";
	private static final int VERSION = 2;

	public DBOpenHelper(Context context)
	{
		super(context, DBNAME, null, VERSION);
		System.out.println(DBNAME);
	}

	public DBOpenHelper(Context context, String name, CursorFactory factory,
			int version)
	{
		super(context, name, factory, version);

	}

	@Override
	public void onCreate(SQLiteDatabase db)
	{
		System.out.println("create table");
		db.execSQL("create table t_person (id integer primary key autoincrement , firstname varchar(30) , lastname varchar(30) , sex varchar(10) ,dob varchar(30) , cellphone varchar(30) , homephone varchar(30) ,email varchar(30) ,regdate varchar(30) ,addr1 varchar(30) ,addr2 varchar(30) ,city varchar(30) , state varchar(30) , zip varchar(30) ,memo varchar(100), f01 varchar(50) ,f02 varchar(100) )");
		db.execSQL("create table t_states (state_id varchar(30), state_name varchar(30))");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('AK', 'Alaska')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('AL', 'Alabama')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('AR', 'Arkansas')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('AZ', 'Arizona')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('CA', 'California')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('CO', 'Colorado')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('CT', 'Connecticut')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('DC', 'District of Columbia')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('DE', 'Delaware')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('FL', 'Florida')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('GA', 'Georgia')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('HI', 'Hawaii')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('IA', 'Iowa')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('ID', 'Idaho')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('IL', 'Illinois')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('IN', 'Indiana')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('KS', 'Kansas')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('KY', 'Kentucky')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('LA', 'Louisiana')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('MA', 'Massachusetts')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('MD', 'Maryland')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('ME', 'Maine')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('MI', 'Michigan')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('MN', 'Minnesota')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('MO', 'Missouri')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('MS', 'Mississippi')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('MT', 'Montana')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('NC', 'North Carolina')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('ND', 'North Dakota')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('NE', 'Nebraska')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('NH', 'New Hampshire')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('NJ', 'New Jersey')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('NM', 'New Mexico')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('NV', 'Nevada')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('NY', 'New York')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('OH', 'Ohio')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('OK', 'Oklahoma')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('OR', 'Oregon')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('PA', 'Pennsylvania')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('RI', 'Rhode Island')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('SC', 'South Carolina')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('SD', 'South Dakota')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('TN', 'Tennessee')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('TX', 'Texas')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('UT', 'Utah')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('VA', 'Virginia')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('VT', 'Vermont')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('WA', 'Washington')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('WI', 'Wisconsin')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('WV', 'West Virginia')");
		db.execSQL("INSERT INTO T_STATES(state_id, state_name) VALUES ('WY', 'Wyoming')");

		System.out.println("end create table");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		System.out.println("drop table");
		db.execSQL("drop table if exists t_person");
		db.execSQL("drop table if exists t_states");
		onCreate(db);
	}
}
